package com.itggm.controller;

import com.itggm.Result.ResponseResult;
import com.itggm.dto.ScoreExportDTO;
import com.itggm.dto.ScorePageDTO;
import com.itggm.pojo.Score;
import com.itggm.service.ScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: ggm
 * @data 2024年12月30日 11:03
 */
@Slf4j
@RestController
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;

    /**
     * @Author: ggm
     * @date: 2024/12/30
     * 分页查询
     */
    @RequestMapping("/page")
    public ResponseResult scoreList(@RequestBody ScorePageDTO scorePageDTO) {
        log.info("分页查询:{}", scorePageDTO);
        return scoreService.scoreList(scorePageDTO);
    }

    /**
     * @Author: ggm
     * @date: 2024/12/30
     * 添加或修改
     */
    @PostMapping("/addOrUpdate")
    public ResponseResult addOrUpdateScore(@RequestBody Score score) {
        log.info("添加或修改成绩信息{}", score);
        scoreService.saveOrUpdate(score);
        return ResponseResult.success();
    }

    /**
     * @Author: ggm
     * @date: 2024/12/30
     * 删除成绩
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteScore(@PathVariable Integer id) {
        log.info("删除成绩信息{}", id);
        scoreService.removeById(id);
        return ResponseResult.success();

    }
     /**
      * @Author: ggm
      * @date:  2024/12/30
      * 批量导入
      */
     @PostMapping("batchImport")
     public ResponseResult  batchImport(MultipartFile file){
         log.info("批量导入{}",file);
         return  scoreService.batchImport(file);
     }
      /**
       * @Author: ggm
       * @date:  2025/1/2
       * 导出文件
       */
      @PostMapping("export")
      public void   exportScore(@RequestBody ScoreExportDTO scoreExportDTO, HttpServletResponse response) {
          log.info("导出成绩信息{}",scoreExportDTO);
          scoreService.exportScore(scoreExportDTO,response);
      }

}
